// ColorCombo.cpp : implementation file
//

#include "stdafx.h"
#include "RawCAD.h"
#include "ColorCombo.h"
#include "ColorData.h"

// CColorCombo

IMPLEMENT_DYNAMIC(CColorCombo, CComboBoxEx)

CColorCombo::CColorCombo()
{

}

CColorCombo::~CColorCombo()
{
}


BEGIN_MESSAGE_MAP(CColorCombo, CComboBoxEx)
	ON_CONTROL_REFLECT(CBN_SELCHANGE, &CColorCombo::OnCbnSelchange)
END_MESSAGE_MAP()



// CColorCombo message handlers




void CColorCombo::OnCbnSelchange()
{
	// TODO: Add your control notification handler code here
	int nIndex = GetCurSel() ;
	if(nIndex != CB_ERR) 
	{
		CColorData* pData = (CColorData*)GetItemDataPtr(nIndex) ;
		if(pData != (CColorData*) -1)
		{
			//global color needs to change
			g_CurColor = pData->m_rgbColor ;
		}
	}
}


void CColorCombo::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct)
{
	// TODO: Add your specialized code here and/or call the base class
	CColorData* pData = (CColorData*)(lpDeleteItemStruct->itemData) ;
	ASSERT(pData) ;
	delete pData ;
	//CComboBoxEx::DeleteItem(lpDeleteItemStruct);
}


void CColorCombo::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{

	// TODO:  Add your code to draw the specified item

	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC) ;
	CColorData* pData = (CColorData*)(lpDrawItemStruct->itemData) ;
	ASSERT(pData) ;
	CRect rc(lpDrawItemStruct->rcItem) ;

	if(lpDrawItemStruct->itemID == CB_ERR)
		return ;
	if(lpDrawItemStruct->itemAction&(ODA_DRAWENTIRE|ODA_SELECT))
		pData->DrawItem(pDC, rc, lpDrawItemStruct->itemState&ODS_SELECTED) ;
}


void CColorCombo::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{

	// TODO:  Add your code to determine the size of specified item
	lpMeasureItemStruct->itemHeight = 18 ;
}

int CColorCombo::AddItem( COLORREF rgbColor, TCHAR* pszName )
{
	CColorData* pData = new CColorData(rgbColor, pszName) ;

	int nRet = AddString((LPCTSTR)pData) ;
	if(nRet == CB_ERR)
		delete pData ;
	return nRet ;
}
